package com.kk.crowd.handler;

import com.kk.crowd.api.MysqlRemoteService;
import com.kk.crowd.constant.CrowdConstant;
import com.kk.crowd.entity.vo.PortalTypeVO;
import com.kk.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class PortalHandler {

    @Autowired
    private MysqlRemoteService mysqlRemoteService;
    // 加载首页类别<项目> 数据
    @RequestMapping("/")
    public String showPortPage(Model model) {
       /* // 这里实际开发中需要加载数据……
        */

        // 1、调用MySQLRemoteService提供的方法查询首页要显示的数据
        ResultEntity<List<PortalTypeVO>> resultEntity = mysqlRemoteService.getPortalTypeProjectDataRemote ( );

        // 2.检查查询结果
        String result = resultEntity.getResult ( );
        if (ResultEntity.SUCCESS.equals (result)){
            // 3.获取查询结果数据
            List<PortalTypeVO> list = resultEntity.getData ( );
            // 4.存入模型
            model.addAttribute (CrowdConstant.ATTR_NAME_PORTAL_DATA,list);
        }

        // 返回首页，渲染数据
        return "portal";
    }
}
